﻿/*******************************************************************************
 **  Name:                                        **
 **  Description:                                                             **
 **                                                                           **
 **  CDDL: Open Source Initiative (OSI) Approved License                            **
 **                                                                           **
 **  Copyright (c) 2009-2010 Barry "Gian" James  <bjames@munixos.net>         **
 **  All rights reserved.                                                     **
 **                                                                           **
 **  The contents of this file are subject to the terms of the CDDL:          **
 **  Common Development and Distribution License (the "License").             **
 **  You may not use this file except in compliance with the License.         **
 **                                                                           **
 **  You can obtain a copy of the license at $PROJECT_ROOT/LICENSE            **
 **  or http://www.opensolaris.org/os/licensing.  This code is Open Source    **
 **  and you are free to use it within the confines of the license, even      **
 **  for your own closed-source commercial projects, as long as you follow    **
 **  the terms set forth in the CDDL.                                         **
 **                                                                           **
 **  When distributing Covered Code, include this CDDL HEADER in each         **
 **  file and include the License file at $PROJECT_ROOT/LICENSE.              **
 **  If applicable, add the following below this CDDL HEADER, with the        **
 **  fields enclosed by brackets "[]" replaced with your own identifying      **
 **  information: Portions Copyright [yyyy] [name of copyright owner]         **
 **                                                                           **
 ******************************************************************************/
// Created on November 1, 2010, 7:25 AM
// Modified $Date$ by $Author$
// $Id$

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.Xml.Linq;

namespace sat1baf1
{
    public partial class RandMissionPlotForm : Form
    {
        Form _frm = null;

        public RandMissionPlotForm()
        {
            InitializeComponent();

            InitializeData();
        }
        public RandMissionPlotForm(NewMissionForm f)
        {
            InitializeComponent();
            _frm = f;
            InitializeData();
        }

        public Form ReturnTo { get { return _frm; } set { _frm = value; } }
        private void InitializeData()
        {
            IEnumerable<XElement> verbs =
                from x in MissionDB.Instance.Plots.Elements("VERBS").Elements("VERB")
                select x;

            foreach (XElement el in verbs)
            {
                comboVerb.Items.Add((string)el);
            }

            verbs =
                from x in MissionDB.Instance.Plots.Elements("OBJECTS").Elements("OBJECT")
                select x;

            foreach (XElement el in verbs)
            {
                comboObject.Items.Add((string)el);
            }

            verbs =
                from x in MissionDB.Instance.Plots.Elements("LOCATIONS").Elements("LOCATION")
                select x;

            foreach (XElement el in verbs)
            {
                comboLocation.Items.Add((string)el);
            }

            verbs =
                from x in MissionDB.Instance.Plots.Elements("OPPOSITION").Elements("OPPONENT")
                select x;

            foreach (XElement el in verbs)
            {
                comboOpposition.Items.Add((string)el);
            }

            verbs =
                from x in MissionDB.Instance.Plots.Elements("COMPLICATIONS").Elements("COMPLICATE")
                select x;

            foreach (XElement el in verbs)
            {
                comboComplications.Items.Add((string)el);
            }


            RandPlotElems();


        }

        private void btnApply_Click(object sender, EventArgs e)
        {
            StringBuilder sb = new StringBuilder("The agents or team must ");
            sb.Append(comboVerb.SelectedItem.ToString());
            sb.Append(" --> " + comboObject.SelectedItem.ToString());
            sb.Append(" opposed by " + comboOpposition.SelectedItem.ToString());
            sb.Append(" while contending against " + comboComplications.SelectedItem.ToString());
            sb.Append(" problems.  Good luck!");

            ((NewMissionForm)_frm).PlotText = sb.ToString();
 //           MessageBox.Show(_frm.Name + "> " + sb.ToString());
        }

        private void btnRandAll_Click(object sender, EventArgs e)
        {
            RandPlotElems();
        }

        private void RandPlotElems()
        {
            Random rand = new Random((int)DateTime.Now.ToBinary());
            comboVerb.SelectedIndex = rand.Next(comboVerb.Items.Count);
            comboObject.SelectedIndex = rand.Next(comboObject.Items.Count);
            comboOpposition.SelectedIndex = rand.Next(comboOpposition.Items.Count);
            comboLocation.SelectedIndex = rand.Next(comboLocation.Items.Count);
            comboComplications.SelectedIndex = rand.Next(comboComplications.Items.Count);
        }


    }
}
